package com.itheima.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/cookieDemo/*")
public class CookieServlet extends BaseServlet {

    private void test1(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException{
        /*
           创建cookie对象
           将cookie添加到response对象中
           响应客户端

           需求：完成登录页面记住状态操作
           记住我

         */
        Cookie cookieName =new Cookie("username","admin");
        //设置存活时间
        cookieName.setMaxAge(7*24*60*60);
        //设置cookie存储路径：设置在根路径，将来页面获取就不需要考虑存储的路径
        cookieName.setPath("/");
        resp.addCookie(cookieName);
        resp.sendRedirect(req.getContextPath()+"/page/login.jsp");
    }



}
